#include "widget.h"
#include "ui_widget.h"
#include <QGestureEvent>
#include <QDebug>

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    this->grabGesture(Qt::TapGesture);
    this->grabGesture(Qt::TapAndHoldGesture);
    this->grabGesture(Qt::PinchGesture);
    this->grabGesture(Qt::SwipeGesture);
    installEventFilter(this);
}

Widget::~Widget()
{
    delete ui;
}

bool Widget::eventFilter(QObject *watched, QEvent *event){
    if(QGestureEvent * e = dynamic_cast<QGestureEvent *>(event)){
//        qDebug() << "手势事件";
        if(e->gesture(Qt::TapGesture)){
            qDebug() << "点击";
        }
        if(e->gesture(Qt::TapAndHoldGesture)){
            qDebug() << "长按";
        }
        if(e->gesture(Qt::PinchGesture)){
            qDebug() << "pinch";
        }
        if(e->gesture(Qt::SwipeGesture)){
            qDebug() << "swipe";
        }
    }
    return QWidget::eventFilter(watched,event);
}
